const state = {
    token: '',
    userInfo: null
}

const mutations = {
    SET_TOKEN(state, token) {
        state.token = token
    },
    SET_USERINFO(state, userInfo) {
        state.userInfo = userInfo
    }
}

const actions = {
    login({ commit }, credentials) {
        console.log(credentials)
        return new Promise((resolve) => {
            // 模拟异步请求
            setTimeout(() => {
                commit('SET_TOKEN', 'mock-token')
                commit('SET_USERINFO', { name: 'testUser' })
                resolve()
            }, 500)
        })
    }
}

const getters = {
    isAuthenticated: state => !!state.token
}

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}
